package com.example.uiwidgettest;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity{
    private EditText editText;
    private ImageView imageView;
    private ProgressBar progressBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null) {
            actionbar.hide();
        }
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.button);
        editText = (EditText) findViewById(R.id.edit_text);//获得实例
        imageView = (ImageView) findViewById(R.id.image_view);
        button.setOnClickListener(this);
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button button=(Button) findViewById(R.id.button1);
            editText=(EditText) findViewById(R.id.edit_text);
            imageView=(ImageView) findViewById(R.id.image_view);
            progressBar=(ProgressBar) findViewById(R.id.progress_bar);
            button.setOnClickListener(this);
            //切换图片

        /*button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                String inputText=editText.getText().toString();//getText()获取到输入的内容，再调用toString()方法转换为字符串。
                Toast.makeText(MainActivity.this, "inputText", Toast.LENGTH_SHORT).show();//通过Toast将输入的内容显示出来.

            }
        });

   }*/

   @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.button:
                imageView.setImageResource(R.drawable.img_2);
                break;
            default:
                break;
        }
    }




    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button1:
                ProgressDialog progressDialog=new ProgressDialog(MainActivity.this);
                progressDialog.setTitle("This is a ProgressDialog");
                progressDialog.setMessage("Loading...");
                progressDialog.setCancelable(true);
                progressDialog.show();
                 AlertDialog.Builder dialog=new AlertDialog.Builder(MainActivity.this);
                dialog.setTitle("This is Dialog");
                dialog.setMessage("Something important");
                dialog.setCancelable(false);
                dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                dialog.show();
                int progress=progressBar.getProgress();
                progress=progress+10;
                progressBar.setProgress(progress);
                if(progressBar.getVisibility()==View.GONE) {
                    progressBar.setVisibility(View.VISIBLE);
                }else {
                    progressBar.setVisibility(View.GONE);
                }
                break;
            default:
                break;
        }
    }

}
